﻿<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>等级符号专题图</title>
        <style type="text/css">
            body{
                margin: 0;
                overflow: hidden;
                background: #fff;
            }
            #map{
                position: relative;
                height: 510px;
                border:1px solid #3473b7;
            }
            #toolbar {
                position: relative;
                padding-top: 5px;
                padding-bottom: 10px;
            }
        </style>
        <link href='./css/bootstrap.min.css' rel='stylesheet' />
        <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            var map, local, baseLayer, layersID, themeLayer,
            host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host,
            url=host+"/iserver/services/map-china400/rest/maps/China";
            function init(){
                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })]
                });
                baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("China400", url, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
                baseLayer.events.on({"layerInitialized":addLayer});
            }

            function addLayer() {
                map.addLayer(baseLayer);
                map.setCenter(new SuperMap.LonLat(12080677, 4591416), 4);
                map.allOverlays = true;
            }
            function addThemeGraduatedSymbol() {
                removeTheme();
                var themeService = new SuperMap.REST.ThemeService(url,
                                {eventListeners:{"processCompleted": themeCompleted, "processFailed": themeFailed}}),
                        graStyle = new SuperMap.REST.ThemeGraduatedSymbolStyle({
                            positiveStyle: new SuperMap.REST.ServerStyle({
                                markerSize: 50,
                                markerSymbolID: 0,
                                lineColor: new SuperMap.REST.ServerColor(255,165,0),
                                fillBackColor: new SuperMap.REST.ServerColor(255,0,0)
                            })
                        }),
                        themeGraduatedSymbol = new SuperMap.REST.ThemeGraduatedSymbol({
                            expression: "SMAREA",
                            baseValue: 3000000000000,
                            graduatedMode: SuperMap.REST.GraduatedMode.CONSTANT,
                            flow: new SuperMap.REST.ThemeFlow({
                                flowEnabled: true
                            }),
                            style: graStyle
                        }),
                        themeParameters = new SuperMap.REST.ThemeParameters({
                            themes: [themeGraduatedSymbol],
                            datasetNames: ["China_Province_pg"],
                            dataSourceNames: ["China"]
                        });

                themeService.processAsync(themeParameters);
            }

            function themeCompleted(themeEventArgs) {
                if(themeEventArgs.result.resourceInfo.id) {
                    themeLayer = new SuperMap.Layer.TiledDynamicRESTLayer("中国各省面积等级符号专题图",
                            url,
                            {cacheEnabled: false, transparent: true,
                                layersID: themeEventArgs.result.resourceInfo.id},
                            {"maxResolution":"auto"});
                    themeLayer.events.on({"layerInitialized":addThemelayer});
                }
            }
            function addThemelayer() {
                map.addLayer(themeLayer);
            }

            function themeFailed(serviceFailedEventArgs) {
                //doMapAlert("",serviceFailedEventArgs.error.errorMsg,true);
                alert(serviceFailedEventArgs.error.errorMsg);
            }

            function removeTheme() {
                if (map.layers.length > 1) {
                    map.removeLayer(themeLayer, true);
                }
            }
        </script>
    </head>
    <body onload="init()">
        <div id="toolbar">
            <input type="button" class="btn" value="创建专题图" onclick="addThemeGraduatedSymbol()" />
            <input type="button" class="btn" value="移除专题图" onclick="removeTheme()" />
        </div>
        <div id="map"></div>
    </body>
</html>
